import request from "../lib/request";

// 获取所有标签
export async function getAllTags() {
  return request({
    url: "/tags",
    method: "GET",
  });
}

// 创建标签
export async function createTag(data: { name: string; category?: string }) {
  return request({
    url: "/tags",
    method: "POST",
    data,
  });
}

// 根据分类获取标签
export async function getTagsByCategory(category: string) {
  return request({
    url: `/tags/category/${category}`,
    method: "GET",
  });
}

// 搜索标签
export async function searchTags(keyword: string) {
  return request({
    url: "/tags/search",
    method: "GET",
    params: { keyword },
  });
}

// 获取热门标签
export async function getPopularTags(params: { page: number; size: number }) {
  return request({
    url: "/tags/popular",
    method: "GET",
    params,
  });
}

// 获取最新标签
export async function getLatestTags(params: { page: number; size: number }) {
  return request({
    url: "/tags/latest",
    method: "GET",
    params,
  });
}

// 根据ID获取标签
export async function getTagById(id: number) {
  return request({
    url: `/tags/${id}`,
    method: "GET",
  });
}

// 根据名称获取标签
export async function getTagByName(name: string) {
  return request({
    url: `/tags/name/${name}`,
    method: "GET",
  });
}

// 更新标签
export async function updateTag(
  id: number,
  data: { name?: string; category?: string }
) {
  return request({
    url: `/tags/${id}/update`,
    method: "POST",
    data,
  });
}

// 删除标签
export async function deleteTag(id: number) {
  return request({
    url: `/tags/${id}/delete`,
    method: "POST",
  });
}

// 获取标签统计信息
export async function getTagStatistics() {
  return request({
    url: "/tags/statistics",
    method: "GET",
  });
}
